package com.ceprei.gui.web;

import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

/**
 * 解决跨域配置问题
 * @author zhou minghao
 * @date 2024/11/27
 * @description
 */
public class CorsConfig {

    @Bean
    public CorsConfigurationSource corsConfigurationSource() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        config.addAllowedOrigin("*");
        config.setAllowedHeaders(Lists.newArrayList(
                "Authorization", "Content-Type", "imk"
        ));
        config.setAllowedMethods(Lists.newArrayList(
                "GET", "POST", "PUT", "DELETE"
        ));
        source.registerCorsConfiguration("/**", config);
        return source;
    }
}
